<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>
        body{
            display: flex;
            justify-content: center;
            align-items: center;
            height: 600px;
            flex-direction: column;
            background-color: #F2F2F2;
        }
        table{
            border: 1px solid;
            width: 320px;
            height: 120px;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: white;
            box-shadow: 5px 5px 2.5px #888888;
            border-radius: 8px;

        }
        #trButton{
            display: flex;
            justify-content: center;
        }
        #btnRegistry{
            margin-left: 50px;
        }
        tr{
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div>登录</div>
    <table>
        <tr>
            <td>
                <label for="">用户名：</label>
            </td>
            <td>
                <input type="text" name="username" placeholder="请输入用户名">
            </td>
        </tr>
        <tr>
            <td>
                <label for="">密码：</label>
            </td>
            <td>
                <input type="password" name="password">
            </td>
        </tr>
        <tr id="trButton">
            <td>
                <input type="button" value="登录" onclick="lgoin()">
            </td>
            <td>
                <input id="btnRegistry" type="button" value="注册">
            </td>
        </tr>
    </table>

    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src="./config/baseUrl.js"></script>
    <script>
        // $(function(){
        //     console.log('登录页面已经初始化完成。。。。');
        // })
        function lgoin() {
            // console.log('你点了登录按钮');
            // 1、获取用户填写的用户名和密码
            // 2、利用jQuery发送post请求 login?username=XXX&password=XXX /login/:id

            let username = $('[name=username]').val();
            let password = $('[name=password]').val();

            let obj = {
                username, 
                password
            }

            $.post(`${baseUrl}/login`,obj,(res)=>{
                if(res.code===1000){
                    window.location.href='./index.html'
                }else{
                    alert(res.msg)
                }
            })
        }
    </script>
</body>

</html>